<template>
	<view>
		<view v-if="states">
			<cover-image src="../../static/rz.png" class="active"></cover-image>
			<view class="active1">已认证</view>
		</view>
		<view v-else>
			<uni-forms ref="baseForm" :model="list" labelWidth="160rpx" class="form">
				<uni-forms-item label="姓名">
					<uni-easyinput v-model="list.name" placeholder="姓名" />
				</uni-forms-item>
				<uni-forms-item label="身份证号">
					<uni-easyinput v-model="list.idcard" placeholder="身份证号" />
				</uni-forms-item>
				<button class="button" type="primary" @click="rz()">立即认证</button>
			</uni-forms>

		</view>
	</view>
</template>

<script>
	import {
		baseDefaultUrl
	} from '../../config/config'
	export default {
		data() {
			return {
				states: false,
				list: {
					name: '',
					idcard: ''
				}
			}
		},
		onShow() {
			this.getMe()
		},
		methods: {
			getMe() {
				uni.request({
					url: baseDefaultUrl + "/inter/user/get",
					method: 'GET',
					data: {
						"username": uni.getStorageSync('phone'),
					},
					header: {
						"Authorization": uni.getStorageSync('token')
					},
					success: (res) => {
						if (res.data.code != 0) {
							if(res.data.data.deptId == 1) {
								this.states = true
							}
						} else {
							alert(res.data.message)
						}
					}
				})
			},
			rz() {
				// console.log(uni.getStorageSync('phone'))
				// console.log(this.list.name)
				// console.log(this.list.idcard)
				// console.log(baseDefaultUrl)
				uni.request({
					url: baseDefaultUrl + "/inter/user/namer",
					method: 'GET',
					data: {
						"username": uni.getStorageSync('phone'),
						"name": this.list.name,
						"number": this.list.idcard
					},
					header: {
						"Authorization": uni.getStorageSync('token')
					},
					success: (res) => {
						if (res.data.code != 0) {
							setTimeout(function() {
								uni.showToast({
									title: "认证成功",
									icon: 'success',
									duration: 2000
								});
							}, 500);
							uni.navigateTo({
								url: '/pages/shiming/shiming'
							})
						} else {
							uni.showToast({
								title: res.data.message,
								icon: 'error'
							});
						}
					}
				})
			}
		}
	}
</script>

<style scoped>
	.active {
		width: 30%;
		margin: 50rpx auto;
	}

	.active1 {
		width: 100%;
		font-size: 45rpx;
		text-align: center;
		color: #1296db;
		font-weight: bolder;
	}

	.form {
		padding: 20rpx;
	}
</style>